{extend name="lib/common_list" /}
{block name="title"}{/block}
{block name="css"}
{load href="/static/sys/css/common.css" /}
{load href="/static/plugins/select2/css/select2.css" /}
{load href="/static/plugins/bootstrap-datetimepicker/css/bootstrap-datetimepicker.css" /}

{load href="/static/sys/css/skin_0.css" /}
<style>
    .upfile i{padding-right:3px !important;}
    .file{ position:absolute;right:0;top:0;width:100px;height:100px;opacity:0; ilter:alpha(opacity=0);cursor:pointer;margin-bottom: 0px;margin-right: 0px; }
</style>
{/block}
{block name="javascript"}
{load  href="/static/plugins/select2/js/select2.js" /}
{load  href="/static/plugins/bootstrap-datetimepicker/js/bootstrap-datetimepicker.js" /}
{load  href="/static/plugins/bootstrap-datetimepicker/js/locales/bootstrap-datetimepicker.zh-CN.js" /}

<script>
    $(document).ready(function () {
        $("#ok").bind("click", Save);
        $("#cancel").bind("click", function () {
            parent.layer.close(parent.layer_edit_index);
        });

        /**
         * 保存内容
         */
        function Save() {
            var load_index = layer.load(0, { shade: false });

            $.ajax({
                type: 'POST',
                url: "{:url('article/edit')}",
                data: $("#fmNew").serialize(),
                dataType: 'json',
                success: function (data) {
                    if (data.code == 1) {
                        layer.close(load_index);
                        layer.alert(data.msg, function () {
                            parent.refreshtb();
                            //window.close();
                            parent.layer.close(parent.layer_edit_index);
                        });
                    } else {
                        layer.alert(data.msg);
                    }
                }
            })
        }

        $('#cate_name').select2();
        $('#button_name').select2();
    });

    /**
     * 新增图片
     */
    var layer_image_add;
    function coverImg() {
        layer_image_add = layer.open({
            type: 2,
            title: "新增图片",
            area: ['70%', '90%'],
            content: "{:url('upload/image')}?tag=cover_img"
        })
    }
    function shareImg() {
        layer_image_add = layer.open({
            type: 2,
            title: "新增图片",
            area: ['70%', '90%'],
            content: "{:url('upload/image')}?tag=share_img"
        })
    }

    function backgroundImg() {
        layer_image_add = layer.open({
            type: 2,
            title: "新增图片",
            area: ['70%', '90%'],
            content: "{:url('upload/image')}?tag=background_img"
        })
    }

    // 上传成功后的回调，该函数名不能写错
    function getImageUrl(res) {
        if (res.tag == 'cover_img') {
            $('#cover_img_url').val(res.url);
            $('#previewImg_cover').attr('src', res.url);
        } else if (res.tag == 'share_img') {
            $('#share_img_url').val(res.url);
            $('#previewImg_share').attr('src', res.url);
        } else if (res.tag == 'background_img') {
            $('#background_url').val(res.url);
            $('#previewImg_background').attr('src', res.url);
        }
    }

    function categoryValue() {
        var cate_id = $("#cate_name").children('option:selected').attr('cate_id');
        $('#cate_id').val(cate_id);
    }

    function buttonValue() {
        var button_key = $("#button_name").children('option:selected').attr('button_key');
        $('#button_key').val(button_key);
    }

</script>
{/block}

{block name="content"}
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-content">
                    <form method="post" id="fmNew" class="form-horizontal" enctype="multipart/form-data">

                        <div class="form-group">
                            <label class="col-sm-2 control-label">美文标题：</label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" name="title" value="{$Rs.title}" placeholder="美文标题">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">美文类别：</label>
                            <div class="col-sm-8">
                                <select class="form-control" name="cate_name" id="cate_name" onchange="categoryValue()">
                                    <option>请选择分类.....</option>
                                    {volist name="category_list" id="v"}
                                    <option value="{$v.name}" cate_id="{$v.id}" {if($v.name==$Rs.cate_name)} selected {/if}>{$v.name}</option>
                                    {/volist}
                                </select>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">美文跳转按钮：</label>
                            <div class="col-sm-8">
                                <select class="form-control" name="button_name" id="button_name" onchange="buttonValue()">
                                    <option>请选择跳转按钮....</option>
                                    {volist name="button_list" id="v"}
                                    <option value="{$v.name}" button_key="{$v.key}" {if($v.name==$Rs.button_name)} selected {/if}>{$v.name}</option>
                                    {/volist}
                                </select>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">分享次数：</label>
                            <div class="col-sm-8">
                                <input type="number" class="form-control" name="share" value="{$Rs.share}" placeholder="分享次数">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">点击次数：</label>
                            <div class="col-sm-8">
                                <input type="number" class="form-control" name="click" value="{$Rs.click}" placeholder="点击次数">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">排序：</label>
                            <div class="col-sm-8">
                                <input type="number" class="form-control" name="sort" value="{$Rs.sort}" placeholder="越小越靠前">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">状态：</label>
                            <div class="col-sm-8">
                                <select class="form-control" name="status">
                                    {volist name="status_list" id="v"}
                                    <option value="{$key}" {if($key == $Rs.status)} selected {/if}>{$v}</option>
                                    {/volist}
                                </select>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">音乐|视频：</label>
                            <div class="col-sm-8">
                                <select class="form-control" name="status">
                                    {volist name="type_list" id="v"}
                                    <option value="{$key}" {if($key == $Rs.type)} selected {/if}>{$v}</option>
                                    {/volist}
                                </select>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">背景音乐：</label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" name="mp3_url" value="{$Rs.mp3_url}" placeholder="背景音乐url">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">背景图：</label>

                            <div class="col-sm-1">
                                <span class="btn btn-primary btn-sm" style="margin-bottom:0;padding:6px 8px;" onclick="backgroundImg()">
                                    <i class="glyphicon glyphicon-folder-open" style="padding-right:3px;"></i> 背景图<input type="hidden" name="background_url" id="background_url" value="{$Rs.background_url}" />
                                </span>
                            </div>
                            <div class="col-sm-1">
                                <img id="previewImg_background" style="height:34px;float: right;" src="{$Rs.background_url}">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">音乐歌词：</label>
                            <div class="col-sm-8">
                                <textarea class="form-control" name="lyric" placeholder="歌词" cols="100%" rows="3">{$Rs.lyric}</textarea>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">封面图：</label>

                            <div class="col-sm-1">
                                <span class="btn btn-primary btn-sm" style="margin-bottom:0;padding:6px 8px;" onclick="coverImg()">
                                    <i class="glyphicon glyphicon-folder-open" style="padding-right:3px;"></i> 封面图<input type="hidden" name="cover_img_url" id="cover_img_url" value = "{$Rs.cover_img_url}" />
                                </span>
                            </div>
                            <div class="col-sm-1">
                                <img id="previewImg_cover" style="height:34px;float: right;" src="{$Rs.cover_img_url}">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>


                        <div class="form-group">
                            <label class="col-sm-2 control-label">分享标题：</label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" name="share_title" value = "{$Rs.share_title}" placeholder="分享标题">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">分享封面图：</label>

                            <div class="col-sm-1">
                                <span class="btn btn-primary btn-sm" style="margin-bottom:0;padding:6px 8px;" onclick="shareImg()">
                                    <i class="glyphicon glyphicon-folder-open" style="padding-right:3px;"></i> 分享封面图<input type="hidden" name="share_img_url" id="share_img_url" value = "{$Rs.share_img_url}" />
                                </span>
                            </div>
                            <div class="col-sm-1">
                                <img id="previewImg_share" style="height:34px;float: right;" src="{$Rs.share_img_url}">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">美文来源：</label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" name="from_url" value = "{$Rs.from_url}" placeholder="美文来源">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">美文内容:</label>
                            <div class="col-sm-16">
                                <div style='display: inline-block; vertical-align: middle;'>
                                    <!-- 加载编辑器的容器 -->
                                    <script id="content" name="content" type="text/plain">
                                        {$Rs.content}
                                    </script>
                                    <!-- 配置文件 -->
                                    <script type="text/javascript" src="/static/plugins/ueditor/ueditor.config.js"></script>
                                    <!-- 编辑器源码文件 -->
                                    <script type="text/javascript" src="/static/plugins/ueditor/ueditor.all.js"></script>
                                    <!-- 实例化编辑器 -->
                                    <script type="text/javascript">
                                        var ue = UE.getEditor('content');
                                    </script>
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>

                            <div id = 'hidden_input'>
                                <input type="hidden" id="button_key" name="button_key" value = "{$Rs.button_key}"/>
                                <input type="hidden"  name="cate_id" id = "cate_id" value = "{$Rs.cate_id}"/>
                                <input type="hidden"  name="id" id = "id" value = "{$Rs.id}"/>
                            </div>

                            <div id="dg" style="z-index: 9999; position: fixed ! important; right: 50%; top:90%;">
                                <div class="form-group">
                                    <div class="col-sm-12 col-sm-offset-5" >
                                        <button class="btn btn-primary" id="ok" type="button">提交</button>
                                        <button class="btn btn-white" id="cancel" type="button">取消</button>
                                    </div>
                                </div>
                            </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
{/block}